package com.erp.products.inventory.controller;

import com.erp.common.core.controller.BaseController;
import com.erp.common.core.domain.AjaxResult;
import com.erp.common.core.page.TableDataInfo;
import com.erp.products.inventory.domain.Inventory;
import com.erp.products.inventory.domain.InventoryVO;
import com.erp.products.inventory.service.InventoryService;
import com.erp.products.productlist.domain.ErpProducts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/product/inventory")
public class InventoryController  extends BaseController {
    @Autowired
    private InventoryService inventoryService;

    @RequestMapping("/list")
    public TableDataInfo list(ErpProducts erpProducts) {
        startPage();
        List<InventoryVO> list = inventoryService.list(erpProducts);
        System.out.println("最后的list = " + list);
        return getDataTable(list);
    }

    //获取仓列表
    @RequestMapping("/warehouse/list")
    public AjaxResult warehouseList() {
        return AjaxResult.success(inventoryService.getWarehouseList());
    }

    //新增
    @RequestMapping("/add")
    public AjaxResult add(@RequestBody InventoryVO inventoryVo) {
        System.out.println("在contrller中新增的inventoryVo = " + inventoryVo);
        try {
            String result = inventoryService.add(inventoryVo);
            return AjaxResult.success(result);
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }
}
